set more off
local a 20

**************************************************************************************
*** OUTCOMES FROM EXAM DATA FROM 1978
**************************************************************************************

use "Data/NCDS/UKDA-5566-stata9/stata9/exams.dta", clear
rename ncdsid NCDSID

* 0/1 qual at 16 and 18
**************************************************************************************

** england
ge Qual16=e236>0
ge Qual18=e349>0

** scotland
replace Qual16=1 if e240>0
replace Qual18=1 if e389>=7


ge MathGradeO=e276
ge MathGradeC=e264

* AGE 16
**************************************************************************************

ge scot = e415>0

/*
	   e493            byte    %8.0g      LABP       E Mathematics,'O',CSE,anywhere,ever
	   e496            byte    %8.0g      LABP       E Other Maths,'O',CSE,anywhere,ever
	   e499            byte    %8.0g      LABP       E Stats Computing'O',CSE,anywhere,ever
*/
egen sub16Math=rowmin(e493 e496 e499 )


/*
	   e451            byte    %8.0g      LABP       E English,O,CSE,anywhere,ever
*/
ge sub16English = e451 


/*
	   e463            byte    %8.0g      LABP       E Biol,Botany,Zoo,anywhere,ever
	   e466            byte    %8.0g      LABP       E Chemistry 16+,anywhere,ever + physics
	   e469            byte    %8.0g      LABP       E Combined Sci16+,anywhere,ever
	   e472            byte    %8.0g      LABP       E Geology,anywhere,ever
	   e502            byte    %8.0g      LABP       E Other Science,'O',CSE,anywhere,ever
	   e505            byte    %8.0g      LABP       E Physics'O',CSE,anywhere,ever ?
*/
egen sub16Science = rowmin(e463 e466 e469 e472 e502 e505)


/*
	   e454            byte    %8.0g      LABP       E Any Art,O,CSE,anywhere,ever (inc music, drama)
*/
ge sub16Art = e454

/*
	   e484            byte    %8.0g      LABP       E Domestic,'O',CSE,anywhere,ever
	   e487            byte    %8.0g      LABP       E Commercial,'O',CSE,anywhere,ever (inc secre., accounting)	   
	   e490            byte    %8.0g      LABP       E Technical,'O',CSE,anywhere,ever

*/


egen sub16Pract = rowmin(e484 e487 e490)


/*
		e445            byte    %8.0g      LABP       E Mod Lang,Not French,O,CSE,anywhere,ever
		e448            byte    %8.0g      LABP       E French,O,CSE,anywhere,ever
		e457            byte    %8.0g      LABP       E Academic Art,'O',CSE,anywhere,ever
		e460            byte    %8.0g      LABP       E History'O',CSE,anywhere,ever
		e475            byte    %8.0g      LABP       E General Studies'O',CSE,anywhere,ever
		e478            byte    %8.0g      LABP       E Social Sci+Commlaw'O',CSE,anywhere,ever
		e481            byte    %8.0g      LABP       E Other Social Sciences,'O',CSE,anywhere,ever

	   
*/
egen sub16Other = rowmin(e445 e448 e457 e460 e475 e478 e481)



local sublist "Math English Science Art Pract Other"
foreach s in `sublist'{
	ge Sub16_`s'_pass = sub16`s'<=2 if scot==0
}


foreach s in `sublist'{
	ge Sub16_`s'_passGAPass = Sub16_`s'_pass if Qual16>0 & scot==0
}

drop sub*

* AGE 16: Exam entries
**************************************************************************************

// Engligh CSE (England and Wales)
ge EEnglighCSE = e272>=0  & e272!=8 & e272!=6 if scot==0 & e272!=.


// Engligh OL  (England and Wales)
ge EEnglighOL=  e288>=0 &   e288!=8 &   e288!=6 if scot==0 &  e288!=.


// Math CSE (England and Wales)
ge tEMathCSE =      e264>=0 & e264!=8 & e264!=6 if scot==0  & e264!=.
ge tEOtherMathCSE = e268>=0 & e268!=8 & e268!=6 if scot==0  & e268!=.

ge EMathCSE = tEMathCSE+tEOtherMathCSE
replace EMathCSE=1 if EMathCSE==2
drop  tEMathCSE tEOtherMathCSE

// Math OL (England and Wales)
ge tEMathOL   =  e276>=0 &  e276!=8 &  e276!=6 if scot==0 & e276!=.
ge tEFurMathOL=  e280>=0 &  e280!=8 &  e280!=6 if scot==0 & e280!=.
ge tEOthMathOL=  e284>=0 &  e284!=8 &  e284!=6 if scot==0 & e284!=.

ge EMathOL =  tEMathOL + tEFurMathOL + tEOthMathOL
replace EMathOL = 1 if EMathOL==2 | EMathOL==3 
drop tEMathOL tEFurMathOL tEOthMathOL


ge EEnglishAny = EEnglighOL + EEnglighCSE 
replace EEnglishAny = 1 if EEnglishAny==2


ge EMathAny = EMathCSE +EMathOL
replace EMathAny=1 if EMathAny==2


* AGE 18
**************************************************************************************



/*
	e556            byte    %8.0g      LABQ       E Mathematics,'A',anywhere,ever
	e559            byte    %8.0g      LABQ       E Other Maths,'A',anywhere,ever
	e562            byte    %8.0g      LABQ       E Stats Computing'A',anywhere,ever
*/
egen sub18Math=rowmin(e556 e559 e562)


/*
	   e514            byte    %8.0g      LABQ       E English'A',anywhere,ever
*/
ge sub18English = e514 


/*
	e526            byte    %8.0g      LABQ       E Biol,Botany,Zoo,anywhere,ever
	e529            byte    %8.0g      LABQ       E Chemistry 16+,anywhere,ever
	e532            byte    %8.0g      LABQ       E Combined Sci16+,anywhere,ever
	e535            byte    %8.0g      LABQ       E Geology,anywhere,ever
	e565            byte    %8.0g      LABQ       E Other Science,'A',anywhere,ever
	e568            byte    %8.0g      LABQ       E Physics'A',anywhere,ever
*/
egen sub18Science = rowmin(e526 e529 e532 e535 e565 e568)


/*
	e517            byte    %8.0g      LABQ       E Any Art'A',anywhere,ever
*/
ge sub18Art = e517

/*
	e547            byte    %8.0g      LABQ       E Domestic,'A',anywhere,ever
	e550            byte    %8.0g      LABQ       E Commercial,'A',anywhere,ever
	e553            byte    %8.0g      LABQ       E Technical,'A',anywhere,ever

*/


egen sub18Pract = rowmin(e547 e550 e553)


/*

	e508            byte    %8.0g      LABQ       E MLANGAL,NOT French'A',anywhere,ever
	e511            byte    %8.0g      LABQ       E French'A',anywhere,ever
	e520            byte    %8.0g      LABQ       E Academic Art,'A',anywhere,ever
	e523            byte    %8.0g      LABQ       E History'A',anywhere,ever
	e538            byte    %8.0g      LABQ       E General Studies'A',anywhere,ever
	e541            byte    %8.0g      LABQ       E Social Sci+commlaw'A',anywhere,ever
	e544            byte    %8.0g      LABQ       E Other Social Science,'A',anywhere,ever
		   
*/
egen sub18Other = rowmin(e508 e511 e520 e523 e538 e541 e544)


local sublist "Math English Science Art Pract Other"
foreach s in `sublist'{
	ge Sub18_`s'_pass = sub18`s'<=1 if scot==0
}


foreach s in `sublist'{
	ge Sub18_`s'_passGAPass = Sub18_`s'_pass if Qual18>0 & scot==0
}

drop sub*


* clean up and save
**************************************************************************************

keep NCDSID Qual* Sub* E*
sort NCDSID

save scratchdata/ncds_1978_Exams1.dta, replace
